﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DocumentManager
{
    class Program
    {
        static void Main(string[] args)
        {
            //DocumentManager<int>  doc=new DocumentManager<int>();
            //Func<int> action1 = doc.GetDocument;
            //Console.WriteLine(action1().ToString());
            var doc = new DocumentManager<Document>();

            doc.AddDocument(new Document("Title A", "Sample A"));
            doc.AddDocument(new Document("Title B", "Sample B"));
            doc.DisplayAllDocuments();
            if(doc.IsDocmentAvailable)
            {
                Document d = doc.GetDocument();
                Console.WriteLine(d.Content);
            }

            Console.ReadKey();
            
        }

        
    }

    class DocumentManager<TDocument> where TDocument : IDocment
    {
        private readonly Queue<TDocument> documentQueue = new Queue<TDocument>();
        public void AddDocument(TDocument doc)
        {
            lock(this)
            {
                documentQueue.Enqueue(doc);
            }
        }

        public bool IsDocmentAvailable
        {
            get { return documentQueue.Count > 0; }
        }

        public TDocument GetDocument()
        {
            TDocument doc = default(TDocument);
            lock (this)
            {
                doc = documentQueue.Dequeue();
            }

            return doc;
        }

        public void DisplayAllDocuments()
        {
            foreach (TDocument doc in documentQueue)
            {
                Console.WriteLine(doc.Title);
            }
        }
    }

    public interface IDocment
    {
        string Title { get; set; }
        string Content { get; set; }
    }

    public class Document:IDocment
    {
        public Document()
        {
        
        }
        public Document(string title,string content)
        {
            this.Title = title;
            this.Content = content;
        }
        public string Title { get; set; }
        public string Content { get; set; }

       
    }
}
